
import position from '../controller/positionController'
import search from '../controller/searchController'
import profile from '../controller/profileController'
import error from '../controller/errorController'

class Router {

  constructor(options) {
    this.mode = options.mode;
    //路由配置
    this.routes = {
      'position': position,
      'search': search,
      'profile': profile
    }
  }

  loadView(path) {
    if (this.routes[path]) {
      this.routes[path].render();
    } else {
      // 404页面找不到
      error.render();
    }
  }

  go(path) {
    if (this.mode === 'hash') {
      location.hash = path;
    } else {
      console.log('path:', path)
      history.pushState({ path }, '', '?' + path)
    }
    this.loadView(path)
    // position.render();
  }
}

export default Router;